home *** CD-ROM | disk | FTP | other *** search
- /*
- **
- ** Move.c - (C) 1993-97 by Stephan Rupprecht
- ** a move command for AmigaDOS
- **
- ** COMPILER
- ** MaxonC++ 4
- **
- ** LINKER-OPTIONS
- ** small data-/code, no startup-code
- **
- ** HISTORY
- ** Nov-1993 first release
- ** Nov-1994 update
- ** Okt-1997 rewritten
- ** Nov-1997 bugfix, added 'AS' option
- **
- */
-
- #include <dos/dos.h>
- #include <dos/dosextens.h>
-
- #include <pragma/dos_lib.h>
- #include <pragma/exec_lib.h>
-
- /****************************************************************************/
-
- STRPTR VerStr = "\0$VER: move 37.1 ("__DATE2__") © 1997 by Stephan Rupprecht";
- struct Library *DOSBase;
-
- void sprintf(STRPTR PutChData, STRPTR FormatStr, ...);
-
- /****************************************************************************/
-
- LONG main(void)
- {
- LONG ret = RETURN_FAIL;
-
- GetBaseReg();
-
- if(DOSBase = OpenLibrary("dos.library", 37L))
- {
- static struct { STRPTR src, dst; LONG as; } args = { 0L, 0L, DOSFALSE };
- struct RDArgs *rdargs;
- STRPTR p;
- TEXT dst[256];
-
- if(rdargs = ReadArgs("FILE/A,TO/A,AS/S", (LONG *)&args, 0))
- {
- p = PathPart(args.src);
- if((*p == '/') && (*(p+1) == '\0')) *p = '\0';
-
- p = args.src;
- strncpy(dst, args.dst, sizeof(dst));
-
- if(args.as == DOSFALSE)
- {
- if(!(AddPart(dst, FilePart(p), sizeof(dst))))
- {
- SetIoErr(ERROR_LINE_TOO_LONG);
- goto err;
- }
- }
-
- if(Rename(p, dst) == DOSFALSE)
- {
- LONG err = 0L;
-
- if((err = IoErr()) == ERROR_RENAME_ACROSS_DEVICES)
- {
- TEXT cmd[256];
-
- sprintf(cmd, "Copy \"%s\" TO \"%s\" CLONE QUIET ALL", p, dst);
-
- if(!System(cmd, NULL))
- {
- sprintf(cmd, "Delete >NIL: \"%s\" QUIET ALL FORCE", p);
-
- if(!System(cmd, NULL))
- ret = RETURN_OK;
- }
- }
- else SetIoErr(err);
- }
- else ret = RETURN_OK;
- err:
- FreeArgs(rdargs);
- }
-
- if(ret != RETURN_OK) PrintFault(IoErr(), "Move");
- else Printf("Moved %s to %s\n", p, dst);
-
- CloseLibrary(DOSBase);
- }
-
- return(ret);
- }
-
- /****************************************************************************/
-
- void sprintf(STRPTR PutChData, STRPTR FormatStr, ...)
- {
- static ULONG PutChProc = 0x16c04e75;
-
- RawDoFmt(FormatStr, ((STRPTR)(&FormatStr))+4, (void (*)())&PutChProc, PutChData);
- }
-
- /****************************************************************************/
-